//
//  BaseTableViewController.swift
//  sinaWeibo
//
//  Created by 史文杰 on 16/3/8.
//  Copyright © 2016年 swjie87. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController ,VisitorViewDelegate {
    
    var userLogin = false
    
    var visitorLoginView : VisitorView?
    /*
    1.此方法是专门为手写代码准备的，实现了此方法，xib / sb 就会失效，不会加载 xib / sb 中的任何东西。
    2.准备视图层次结构的，-> 根视图(意思准备对应的根视图：UIViewController的话就准备UIView，UITableViewController的话就准备UITableView，)
    3.在根视图没有实例化的时候，不要在此方法内追踪View，会造成递归调用。
    */
    override func loadView()
    {
        //定义一个bool值，判断用户是否登陆，然后准备需要的根视图
        if userLogin
        {
            //登陆 准备UITableView
            super.loadView()
        }
        else
        {
            //实例化的visitView 虽然没有设置frame，但是会在 viewWillLayoutSubviews() 方法内自动设置正确的frame 即屏幕的frame
            visitorLoginView = VisitorView()
            // visitorView.backgroundColor = UIColor.whiteColor()
            visitorLoginView?.visitorDelegate = self
            view = visitorLoginView
            
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "userWillLogin")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegisterBtn")
            navigationItem.leftBarButtonItem?.tintColor = UIColor.orangeColor()
            navigationItem.rightBarButtonItem?.tintColor = UIColor.orangeColor()

//            visitorLoginView?.userLoginBtnClick = { ()->() in
//                print("闭包调用")
//            }
        }
        
    }
    
    
    //MARK: VisitorViewDelegate 协议方法
    func userWillLogin() {
        
    }
    func userWillRegisterBtn() {
        print("用户将要注册")
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }
    
    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
    
    // Configure the cell...
    
    return cell
    }
    */
    
    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want the specified item to be editable.
    return true
    }
    */
    
    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    // Delete the row from the data source
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
    }
    */
    
    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
    
    }
    */
    
    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want the item to be re-orderable.
    return true
    }
    */
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
